home *** CD-ROM | disk | FTP | other *** search
Java Source | 2002-11-09 | 2.4 KB | 89 lines |
- //
- // The contents of this file are subject to the BadBlue End User License
- // Agreement (the "EULA"); you may not use this file except in
- // compliance with the EULA. You may obtain a copy of the EULA at
- // http://badblue.com/down.htm .
- //
- // Software distributed under the EULA is distributed on an "AS IS" basis,
- // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the EULA
- // for the specific language governing rights and limitations under the
- // EULA.
- //
- // The Initial Developer of this code under the EULA is Working Resources,
- // Inc., Atlanta, GA UNITED STATES. All Rights Reserved.
- //
-
- //
- package ShareOffice;
-
- //
- import java.net.*;
- import java.io.*;
-
- //
- public class HTTPGet {
- //
- public HTTPGet() {
- }
- //
- public String Read(String sURL) {
- try {
- URL u = new URL(sURL);
- InputStream is = u.openStream();
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- String s = "";
- String sLine;
- while ((sLine = br.readLine()) != null) {
- // System.out.println(sLine);
- s += sLine;
- }
- return (s);
- } catch (Exception e) {
- return "Error, no data available: " +
- e.getMessage();
- }
- }
- //
- public String Read(String sURL, String sUsername, String sPassword) {
- try {
- URL u = new URL(sURL);
- String sUP = sUsername + ":" + sPassword;
- String sUPencoded = new sun.misc.BASE64Encoder().encode(sUP.getBytes());
- URLConnection urlConn = u.openConnection();
- urlConn.setRequestProperty("Authorization", "Basic " + sUPencoded);
- urlConn.setDoInput(true);
- urlConn.setUseCaches (false);
- urlConn.setDoOutput(true);
- DataOutputStream printout = new DataOutputStream(urlConn.getOutputStream());
- int nCursor;
- String sContent = "";
- if ((nCursor = sURL.indexOf('?')) >= 0) {
- sContent = sURL.substring(nCursor + 1);
- }
- printout.writeBytes(sContent);
- printout.flush();
- printout.close();
- // DataInputStream input = new DataInputStream(urlConn.getInputStream());
- BufferedReader input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
- String s = "";
- String sLine;
- while (null != ((sLine = input.readLine()))) {
- // System.out.println(sLine);
- s += sLine;
- }
- input.close();
- return (s);
- } catch (Exception e) {
- return "Error, no data available: " +
- e.getMessage();
- }
- }
-
- // Private members.
- //
- }
-
- // <EOF>
- //
-